package com.kyzh.core.pager.home

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.google.android.material.tabs.TabLayoutMediator
import com.gushenge.core.beans.Tab
import com.kyzh.core.R
import com.kyzh.core.adapters.v3.HomeFindTabAdapter
import kotlinx.android.synthetic.main.fragment_homefind.*


class HomeFindFragment : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_homefind, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val titles = arrayListOf<Tab>(
                Tab(R.drawable.ic_homefind_0,getString(R.string.platformRecom)),
                Tab(R.drawable.ic_homefind_1,getString(R.string.gameNews)),
                Tab(R.drawable.ic_homefind_2,getString(R.string.gameStrategy)),
                Tab(R.drawable.ic_homefind_3,getString(R.string.newGameEval)),
                Tab(R.drawable.ic_homefind_4,getString(R.string.newGameTravel))
        )
        val adapter = HomeFindTabAdapter(this)
        viewpager.adapter = adapter
        viewpager.currentItem = 0
        TabLayoutMediator(tabLayout,viewpager){ tab,position->
            tab.icon = ContextCompat.getDrawable(requireActivity(),titles[position].image)
            tab.text = titles[position].text
        }.attach()
    }
}